package cn.wolfcode.student;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("cn.wolfcode.student.mapper")
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public WebMvcConfigurer configurer() {
        return new WebMvcConfigurer() {
            //重写父类的跨域请求处理接口
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                            .allowedOrigins("*")//放行哪些域
//                        .allowedOriginPatterns("*")
                        .allowCredentials(true)//是否发送cookie信息
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")//哪些请求放行
                        .allowedHeaders("*")//头信息放行
                        .allowedHeaders("version", "v1.0")//自定义头信息
                ;
            }
        };
    }
}

